package pl.edu.mimuw.irs.rcp.controller.editor.workflow.part;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import org.eclipse.draw2d.FreeformLayer;
import org.eclipse.draw2d.FreeformLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;

import pl.edu.mimuw.irs.core.model.petrinet.INode;
import pl.edu.mimuw.irs.core.model.petrinet.workflow.Workflow;
import pl.edu.mimuw.irs.rcp.controller.editor.workflow.policy.NodeComponentEditPolicy;
import pl.edu.mimuw.irs.rcp.controller.editor.workflow.policy.WorkflowXYLayoutEditPolicy;

/**
 * @author Jakub Rauch
 * Created on: 2009-05-16
 */
public class WorkflowEditPart extends AbstractGraphicalEditPart {

	// *** Methods
	
	@Override
	protected IFigure createFigure() {
		/*Figure figure = new FreeformLayer();
		figure.setBorder(new MarginBorder(10));
		//Create a layout for the graphical screen
		
		FreeformLayout freeformLayout = new FreeformLayout();
		GridLayout gridLayout = new GridLayout();
		gridLayout.numColumns = 70;
		gridLayout.horizontalSpacing = 0;
		gridLayout.verticalSpacing = 0;
		gridLayout.marginHeight = 0;
		gridLayout.marginWidth = 0;
		figure.setLayoutManager(freeformLayout);
		return figure;*/
		
		FreeformLayer freeformLayer = new FreeformLayer();
		freeformLayer.setLayoutManager(new FreeformLayout());
		return freeformLayer;
	}
	
	
	
    @Override
    protected List<INode> getModelChildren() {
		//List<IRSPlace> places = new LinkedList<IRSPlace>();
		//places.add(((IRSWorkflow)getModel()).getRootPlace());
		//return places;
    	Set<INode> children = ((Workflow)getModel()).getAllNodes();
    	return new LinkedList<INode>(children);
    }

	@Override
	public boolean isSelectable() {
		return true;
	}
	
    @Override
	protected void createEditPolicies() {
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new WorkflowXYLayoutEditPolicy());
		installEditPolicy(EditPolicy.COMPONENT_ROLE, new NodeComponentEditPolicy());
	}

}
